<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<%@ include file="/WEB-INF/page/include.inc.jsp"%>
	<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/styles/table.css">
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>Insert title here</title>
	<script>
		$(document).ready(function() {
			
			//initCurrTime();
		});
		
		/*ajaxPost提交*/
		function ajaxPost(url, param, callBackFun) {
			if(!param) {
				param = {};
			}
			$.post(url, param, function(data) {
				if (callBackFun instanceof Function) {
					callBackFun.call(this, data);
				}
			});
		}
		
		function queryRole() {
			ajaxPost("queryRole", {}, callBackRole);
		}
		
		function callBackRole(data) {
			var selector = $('#roleId');
			for(var i=0; i<data.rows.length; i++) {
				if(data.rows[i].name != null) {
					selector.append("<option value="+data.rows[i].id+">"+data.rows[i].name+"</option>");
				}
			}
			var roleId ='${operator.roleId}';
			$("#roleId").find("option[value="+roleId+"]").attr("selected",true);
		}
		
		function callBackRole2(data) {
			var obj = document.getElementById("roleId");
			for(var i=0; i<data.rows.length; i++) {
				obj.options.add(new Option(data.rows[i].name, data.rows[i].id));
				var roleId ='${operator.roleId}';
				if(obj.options[i].value == roleId) {
					obj.options[i].selected = true;
		        }
			}
		}
		
		function submitForm(tabName) {
		    $("#formId").ajaxSubmit(function(data) {
		    	var obj = eval ("(" + data + ")");
		    	if (obj.success){
					msgAlert('信息提示', '操作成功', 'info', function() {
						self.parent.refreshTab(tabName);
						self.parent.closeCurrTab();
					});
				}
				else {
					msgAlert('错误提示', obj.message, 'error', null);
				}
		    });
		}
	</script>
</head>
<body>
	<div>
        <div style="padding:20px 0px 10px 100px">
        <form id="formId" name="formId" action="update" method="post">
        	<input type="hidden" name="id" value="${operator.id}"></input>
            <table>
            	<tr>
                    <td>用户名:</td>
                    <td>${operator.id}</td>
                </tr>
                <tr>
                    <td>姓名:</td>
                    <td><input type="text" name="name" value="${operator.name}"></input></td>
                </tr>
                <tr>
                    <td>性别:</td>
                    <td>
                    	<input type="radio" name="sex" value="1" ${operator.sex == '1' ? "checked='checked'" : ""}>男</input>
                    	<input type="radio" name="sex" value="2" ${operator.sex == '2' ? "checked='checked'" : ""}>女</input>
                    </td>
                </tr>
                <tr>
                    <td>出生日期:</td>
                    <td><input type="text" name="birthDate" class="Wdate" onClick="WdatePicker({dateFmt:'yyyy/MM/dd'})" value="<fmt:formatDate value="${operator.birthDate}" pattern="yyyy/MM/dd"/>"></input></td>
                </tr>
                <tr>
                    <td>住址:</td>
                    <td><input type="text" name="address" value="${operator.address}"></input></td>
                </tr>
                <tr>
                    <td>手机:</td>
                    <td><input type="text" name="mobile" value="${operator.mobile}"></input></td>
                </tr>
                <tr>
                    <td>电话:</td>
                    <td><input type="text" name="phone" value="${operator.phone}"></input></td>
                </tr>
                <tr>
                    <td>角色:</td>
                    <td>
						<select id="roleId" name="roleId" style="width: 150px">
							<option value="">请选择</option>
	                    	<c:forEach items="${roleList}" var="role">
	                    		<option value="${role.id}" ${role.id eq operator.roleId ? 'selected="selected"' : ''}>${role.name}</option>
	                    	</c:forEach>
						</select>
					</td>
                </tr>
            </table>
            
            <div style="padding:20px 0 10px 70px">
				<input class="button" type="button" value="提交" onclick="submitForm('操作员管理');"></input>
	            <input class="button" type="button" value="取消" onclick="parent.closeCurrTab();"></input>
            </div>
        </form>
        </div>
    </div>
</body>
</html>
